package org.xs.big_event.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.xs.big_event.common.JWT_lanJie;
import org.xs.big_event.dao.user.UserRepository;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    private JWT_lanJie jwtLanJie;
    UserRepository userRepository;
    @Autowired
    WebConfig(UserRepository userRepository,JWT_lanJie jwtLanJie){
        this.userRepository=userRepository;
        this.jwtLanJie=jwtLanJie;
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtLanJie)
                .addPathPatterns("/api/**") // 指定拦截的路径模式（例如所有/api开头的请求）
                .excludePathPatterns(                          // 排除不需要验证的接口
                        "/api/user/login",                     // 登录接口
                        "/api/user/register",                  // 注册接口
                        //api/user/logout",                    // 登出接口
                        "/error"                                // 错误页面
                );    }
}
